'use strict';
var go = require('gojs');
/////////////////////////////////////
// gojs
// =====================
// liuyp 2019年2月26日10:35:12
/////////////////////////////////////
function gojs() {
    function initGo1(attr, scope) {
        var $ = go.GraphObject.make;
        var myDiagram = $(go.Diagram, attr.id, {
            "initialContentAlignment": go.Spot.Center,
            //"toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom,
            "clickCreatingTool.archetypeNodeData": {
                text: "new node"
            },
            "undoManager.isEnabled": true
        });
        myDiagram.nodeTemplate = $(go.Node, "Auto", new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "RoundedRectangle", {
            parameter1: 20,
            fill: $(go.Brush, "Linear", { 0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)" }),
            stroke: null,
            portId: "",
            fromLinkable: true,
            fromLinkableSelfNode: true,
            fromLinkableDuplicates: true,
            toLinkable: true,
            toLinkableSelfNode: true,
            toLinkableDuplicates: true,
            cursor: "pointer"
        }), $(go.TextBlock, {
            font: "bold 11pt helvetica, bold arial, sans-serif",
            editable: true
        }, new go.Binding("text").makeTwoWay()));
        myDiagram.nodeTemplate.selectionAdornmentTemplate = $(go.Adornment, "Spot", $(go.Panel, "Auto", $(go.Shape, {
            fill: null,
            stroke: "blue",
            strokeWidth: 2
        }), $(go.Placeholder)), $("Button", {
            alignment: go.Spot.TopRight,
            click: addNodeAndLink
        }, $(go.Shape, "PlusLine", {
            width: 6,
            height: 6
        })));
        function addNodeAndLink(e, obj) {
            var adornment = obj.part;
            var diagram = e.diagram;
            diagram.startTransaction("Add State");
            var fromNode = adornment.adornedPart;
            var fromData = fromNode.data;
            var toData = { text: "new" };
            var p = fromNode.location.copy();
            p.x += 200;
            toData.loc = go.Point.stringify(p);
            var model = diagram.model;
            model.addNodeData(toData);
            var linkdata = {
                from: model.getKeyForNodeData(fromData),
                to: model.getKeyForNodeData(toData),
                text: "transition"
            };
            model.addLinkData(linkdata);
            var newnode = diagram.findNodeForData(toData);
            diagram.select(newnode);
            diagram.commitTransaction("Add State");
            diagram.scrollToRect(newnode.actualBounds)
        }
        myDiagram.linkTemplate = $(go.Link, {
            curve: go.Link.Bezier,
            adjusting: go.Link.Stretch,
            reshapable: true,
            relinkableFrom: true,
            relinkableTo: true,
            toShortLength: 3
        }, new go.Binding("points").makeTwoWay(), new go.Binding("curviness"), $(go.Shape, {
            strokeWidth: 1.5
        }), $(go.Shape, {
            toArrow: "standard",
            stroke: null
        }), $(go.Panel, "Auto", $(go.Shape, {
            fill: $(go.Brush, "Radial", { 0: "rgb(240, 240, 240)", 0.3: "rgb(240, 240, 240)", 1: "rgba(240, 240, 240, 0)" }),
            stroke: null
        }), $(go.TextBlock, "transition", {
            textAlign: "center",
            font: "9pt helvetica, arial, sans-serif",
            margin: 4,
            editable: true
        }, new go.Binding("text").makeTwoWay())));
        scope.ngModel = myDiagram;
        scope.callback && scope.callback()
    }
    return {
        restrict: 'EA',
        scope: {
            ngModel: '=',
            callback: '&'
        },
        link: function(scope, element, attrs) {
            initGo1(attrs, scope)
        }
    }
}
exports = module.exports = gojs;